package com.apes.fn.scm.advancePayment;

import com.apes.scm.masterdata.party.repository.PartyRoleRepository;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.Optional;

/**
 * Creator: zouyc
 * CreateDate: 2021-04-08 10:02
 * Description:
 **/
@Deprecated
public abstract class AbstractAPayBase {
    @Autowired
    private AdvancePaymentRepository advancePaymentRepository;
    @Autowired
    private PartyRoleRepository partyRoleRepository;

    private String type;
    private AdvancePayment advancePayment;

    public AbstractAPayBase(AdvancePayment advancePayment){
        if(advancePayment == null) throw new RuntimeException("定金信息为空，不予操作");
        this.advancePayment = advancePayment;
    }

    public AdvancePayment excute(){
        check();  //检查一些操作信息
        operate(); //设值操作
        return advancePaymentRepository.saveAndFlush(advancePayment);
    }




    protected void AuditEx(AdvancePayment advancePayment,String operatorId){
        advancePayment.setDateApprove(new Date());
        advancePayment.setApproveUID(Optional.ofNullable(partyRoleRepository.findOne(operatorId)).orElseThrow(()->new RuntimeException("操作人员不存在，人员编码：" + operatorId)));
    }


    public abstract void check();
    public abstract void operate();
    /**
     * 定金单审核
     */
    private void AuditCheck(){
        if(advancePayment.getDateApprove() != null || advancePayment.getApproveUID() != null) throw new RuntimeException("该定金单已执行过该操作，无需重复执行"); //检查是否已经有审核信息
    }
}